<!-- 消息中心 -->
<template>
	<view>
		
		
		 <u-sticky bgColor="#fff">
		    <u-tabs 
			:list="tabList" 
			@change="changeTab"
			active-color="#FD7885"
			height='88'
			bar-width='58'
			bar-height='4'
			item-width='375'
			style="border-bottom: 1px solid #EDEDED;border-top: 1px solid #EDEDED;"
			font-size='26'
			:current='tabCurrent'
			></u-tabs>
		  </u-sticky>
		  
		  
		
		<view v-if="msgList.length" class="flex padding-tb-sm u-border-bottom message_list_item" v-for="(item,index) in msgList"
			:key='index' @click="goNav('/me/message/info?id='+item.id)" style="margin-left: 30rpx;">
			<u-image src="@/me/static/message/xitong.png" width="70rpx" mode="widthFix" v-if='tabCurrent==1'></u-image>
			<u-image src="@/me/static/message/fuwu.png" width="70rpx" mode="widthFix" v-else></u-image>
			<view class="flex-sub margin-left">
				<view class="flex justify-between">
					<view style="font-weight: bold;
font-size: 28rpx;
color: #1A1A1A;
width: 300rpx;
" class="text-ellipsis one-text-ellipsis">{{item.title}}</view>
					<view style="font-weight: 500;
font-size: 22rpx;
color: #CCCCCC;">{{item.createAt}}</view>
				</view>
				<view class="text-ellipsis one-text-ellipsis" style="font-weight: 500;
font-size: 24rpx;
color: #999999;
padding-top: 18rpx;
">{{item.content}}</view>
			</view>
		</view>
		<empty v-if="!msgList.length" title="暂无消息" :isShow="false"></empty>
		<!-- <view class="page-box" v-if="!msgList.length">
			<view class="centre">
				<image src="../static/none.png" mode=""></image>
				<view class="tips">
					暂无消息
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				page: 1,
				limit: 10,
				msgList: [],
				 tabList: [{
						name: '系统消息',
					}, {
						name: '服务消息',
				}],
				tabCurrent:0
			}
		},
		onLoad() {
			this.getMsg()
		},
		methods: {
			goNav(url) {
				uni.navigateTo({
					url
				})
			},
			changeTab(item) {
				   this.tabCurrent = item
				   this.page = 1
				   this.msgList = []
				   this.getMsg()
			},
			getMsg() {
				uni.showLoading({
					title: '加载中'
				})
				let data = {
					page: this.page,
					limit: this.limit,
					state: this.tabCurrent==1?5:303
				}
				this.$u.api.message(data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							this.msgList = res.data.list
							uni.stopPullDownRefresh();
							return
						}
						this.msgList = [...this.msgList, ...res.data.list]
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
					uni.hideLoading()
					uni.stopPullDownRefresh();
				})
			}
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getMsg()
		},
		onPullDownRefresh: function() {
			this.page = 1;
			// this.msgList = []
			this.getMsg()
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: rgba(247, 248, 255, 1);
	}

	.message_list_item{
		width: 690rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 30rpx 20rpx;
		margin-top: 20rpx;
	}
	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 360rpx;
			height: 360rpx;
			// margin-bottom: 20rpx;
			margin: 0 auto 20rpx;
			// border: 1px dotted #000000;
		}

		.tips {
			font-size: 34rpx;
			color: #5074FF;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 600rpx;
			border-radius: 32rpx;
			line-height: 90rpx;
			color: #ffffff;
			font-size: 34rpx;
			background: #5074FF;
		}
	}
</style>